import { Button, Tooltip } from 'antd';
import { getColorTextLoadMap, tooltipLength } from '@/utils';
import pageStyles from '@/common/pageLayout.less';
import { Fragment } from 'react';
import { EditOutlined, CloseCircleOutlined } from '@ant-design/icons';
import { ManageCommonAPI } from '@/pages/type';
import { tableMoreBtnConfig } from '@/utils/myutilConfig';
// 操作按钮
const Operation = (curRes: Record<string, any>, clickFnc: SupplierManageAPI.IOperationClick, record: Record<string, any>) => {
  let operationArray: any = [];

  /** 一个按钮都没有时展示*/
  const Disable = (
    <Fragment key={record?.id + '--Disable'}>
      <Button style={{ color: '#000' }} className="manageBtntTxtStyle" type={'link'} size={'small'} disabled>
        --
      </Button>
    </Fragment>
  );

  /** 更多按钮配置 */
  const otherBtnConfig: ManageCommonAPI.TableMoreBtnConfigApi[] = [
    {
      icon: <EditOutlined />,
      btnName: '编辑',
      clickFnc: clickFnc,
      clickType: 'onEdit',
      isVisible: curRes?.['/supplierInfoController/edit'] && !record?.cancelerID,
    },
    {
      icon: <CloseCircleOutlined />,
      btnName: '作废',
      clickFnc: clickFnc,
      clickType: 'onCancel',
      isVisible: curRes?.['/supplierInfoController/cancel'] && !record?.cancelerID,
    },
  ];

  const ohterBtn = tableMoreBtnConfig(otherBtnConfig, record);
  operationArray = ohterBtn;
  operationArray = operationArray?.filter((itemBtn: any) => itemBtn);
  return operationArray && operationArray?.length > 0 ? operationArray : [Disable];
};

const getTableColumns = (curRes: Record<string, any>, clickFnc: SupplierManageAPI.IOperationClick) => {
  return [
    {
      title: '单位名称',
      dataIndex: 'fullName',
      key: 'fullName',
      width: 200,
      visible: true,
      fixed: 'left',
      unDrag: true,
      sorter: (a: any, b: any) => (a?.fullName > b?.fullName ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <a
            onClick={() => {
              if (curRes?.['/supplierInfoController/getSupplierById/{id}']) {
                clickFnc?.onView(record);
              }
            }}
            style={{ color: '100%' }}
          >
            <Tooltip title={tooltipLength(text, 50)}>
              <span className={pageStyles['over-flow-hidden']}>{text || '--'}</span>
            </Tooltip>
          </a>
        );
      },
    },
    {
      title: '企业属性',
      dataIndex: 'enterpriseType',
      key: 'enterpriseType',
      width: 150,
      visible: true,
      render: (text: number) => {
        return (
          // <Tooltip title={text ? tooltipLength(text, 50) : ''}>
          //   <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          // </Tooltip>
          <span>{text == 0 ? '大陆' : text == 1 ? '港澳台' : text == 2 ? '境外' : '--'}</span>
        );
      },
    },
    {
      title: '法定代表人',
      dataIndex: 'legalName',
      key: 'legalName',
      width: 130,
      visible: true,
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <Tooltip title={tooltipLength(text, 100)}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '所属区域',
      dataIndex: 'registerAddress',
      key: 'registerAddress',
      width: 160,
      visible: true,
      render: (text: string | null, record: Record<string, any>) => {
        // let newText: string | null = renderRegionText(record);
        // return (
        //   <Tooltip title={newText}>
        //     <span className={pageStyles['over-flow-hidden']}>{newText}</span>
        //   </Tooltip>
        // );
        return (
          <Tooltip title={tooltipLength(text, 100)}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '统一社会信用代码',
      dataIndex: 'creditID',
      key: 'creditID',
      width: 220,
      visible: true,
      render: (text: string | null) => {
        return (
          <Tooltip title={text ? tooltipLength(text, 50) : ''}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },

    {
      title: '单位地址',
      dataIndex: 'workAddress',
      key: 'workAddress',
      width: 160,
      visible: true,
      sorter: (a: any, b: any) => (a?.workAddress > b?.workAddress ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <Tooltip title={tooltipLength(text, 100)}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '首要联系人',
      dataIndex: 'contactName',
      key: 'contactName',
      width: 140,
      visible: true,
      // sorter: (a: any, b: any) => (a?.contactName > b?.contactName ? 1 : -1),
      render: (text: string | null) => {
        const { colorText, color } = getColorTextLoadMap(text);
        return (
          <span
            className={pageStyles['over-flow-hidden']}
            style={{
              color,
            }}
          >
            {colorText ? colorText : '--'}
          </span>
        );
      },
    },
    {
      title: '首要联系人电话',
      dataIndex: 'contactMobile',
      key: 'contactMobile',
      width: 200,
      visible: true,
      sorter: (a: any, b: any) => (a?.contactMobile > b?.contactMobile ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <Tooltip title={tooltipLength(text, 100)}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '是否有效',
      dataIndex: 'supplierState',
      key: 'supplierState',
      width: 120,
      visible: true,
      sorter: (a: any, b: any) => (a?.supplierState > b?.supplierState ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        return <span className={pageStyles['over-flow-hidden']}>{Number(text) == 0 ? '是' : '否'}</span>;
      },
    },
    {
      title: '开户行名称',
      dataIndex: 'bankName',
      key: 'bankName',
      width: 150,
      visible: true,
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <Tooltip title={tooltipLength(text, 100)}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '开户行账号',
      dataIndex: 'bankAccount',
      key: 'bankAccount',
      width: 200,
      visible: true,
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <Tooltip title={tooltipLength(text, 100)}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '注册电话',
      dataIndex: 'registerPhone',
      key: 'registerPhone',
      width: 160,
      visible: true,
      sorter: (a: any, b: any) => (a?.registerPhone > b?.registerPhone ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <Tooltip title={tooltipLength(text, 100)}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },

    {
      title: '创建时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.createTime > b?.createTime ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text ? text : ''}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '创建人',
      dataIndex: 'createrName',
      key: 'createrName',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.createrID > b?.createrID ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text ? text : ''}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '创建岗位',
      dataIndex: 'createPositionName',
      key: 'createPositionName',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.createPositionID > b?.createPositionID ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text ? text : ''}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '创建部门',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.createDepartmentID > b?.createDepartmentID ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '创建公司',
      dataIndex: 'createCompanyName',
      key: 'createCompanyName',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.createCompanyID > b?.createCompanyID ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '作废类型',
      dataIndex: 'cancelTypeName',
      key: 'cancelTypeName',
      width: 160,
      visible: false,
      sorter: (a: any, b: any) => (a?.cancelType > b?.cancelType ? 1 : -1),
      render: (text: string | null) => {
        const { color, colorText } = getColorTextLoadMap(text);
        return (
          <Tooltip title={colorText ? colorText : ''}>
            <span className={pageStyles['over-flow-hidden']} style={{ color: color }}>
              {colorText ? colorText : '--'}
            </span>
          </Tooltip>
        );
      },
    },
    {
      title: '作废原因',
      dataIndex: 'cancelReason',
      key: 'cancelReason',
      width: 150,
      visible: false,
      render: (text: string | null) => {
        return (
          <Tooltip title={tooltipLength(text, 100)}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '作废时间',
      dataIndex: 'cancelTime',
      key: 'cancelTime',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.cancelTime > b?.cancelTime ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '作废人',
      dataIndex: 'cancelerName',
      key: 'cancelerName',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.cancelerID > b?.cancelerID ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '作废岗位',
      dataIndex: 'cancelPositionName',
      key: 'cancelPositionName',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.cancelPositionID > b?.cancelPositionID ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '作废部门',
      dataIndex: 'cancelDepartmentName',
      key: 'cancelDepartmentName',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.cancelDepartmentID > b?.cancelDepartmentID ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '作废公司',
      dataIndex: 'cancelCompanyName',
      key: 'cancelCompanyName',
      width: 150,
      visible: false,
      sorter: (a: any, b: any) => (a?.cancelCompanyID > b?.cancelCompanyID ? 1 : -1),
      render: (text: string | null) => {
        return (
          <Tooltip title={text}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 230,
      visible: true,
      unDrag: true,
      fixed: 'right',
      render: (text: any, record: any) => {
        return (
          <div
            style={{
              display: 'flex',
            }}
          >
            {Operation(curRes, clickFnc, record)}
          </div>
        );
      },
    },
  ];
};

/**变更记录配置 */
const modifyJsonConfig: Record<string, any>[] = [
  {
    code: 'fullName',
    name: '企业名称',
  },
  {
    code: 'shortName',
    name: '企业简称',
  },
  {
    code: 'registerAddress',
    name: '注册地址',
  },
  {
    code: 'registerCapital',
    name: '注册资本',
  },
  {
    code: 'legalName',
    name: '法定代表人',
  },
  {
    code: 'registerTypeName',
    name: '企业类型',
  },
  {
    code: 'registerBegin',
    name: '开始时间',
  },
  {
    code: 'registerFinish',
    name: '结束时间',
  },
  {
    code: 'businessScope',
    name: '经营范围',
  },
  {
    code: 'registerSizeName',
    name: '企业规模',
  },
  {
    code: 'supplyTypeName',
    name: '供货分类',
  },
  {
    code: 'materialTypeName',
    name: '物料类型',
  },
  {
    code: 'bankName',
    name: '开户行名称',
  },
  {
    code: 'bankAccount',
    name: '开户行账号',
  },
];

export { getTableColumns, modifyJsonConfig };

// {
//   title: '单位类型',
//   dataIndex: 'registerTypeName',
//   key: 'registerTypeName',
//   width: 120,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.registerType > b?.registerType ? 1 : -1),
//   render: (text: string | null) => {
//     const { colorText, color } = getColorTextLoadMap(text);
//     return (
//       <span
//         className={pageStyles['over-flow-hidden']}
//         style={{
//           color,
//         }}
//       >
//         {colorText ? colorText : '--'}
//       </span>
//     );
//   },
// },
// {
//   title: '企业规模',
//   dataIndex: 'registerSizeName',
//   key: 'registerSizeName',
//   width: 120,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.registerSize > b?.registerSize ? 1 : -1),
//   render: (text: string | null) => {
//     const { colorText, color } = getColorTextLoadMap(text);
//     return (
//       <span className={pageStyles['over-flow-hidden']} style={{ color }}>
//         {colorText ? colorText : '--'}
//       </span>
//     );
//   },
// },
// {
//   title: '授权代表',
//   dataIndex: 'authName',
//   key: 'authName',
//   width: 120,
//   visible: true,
//   // sorter: (a: any, b: any) => (a?.authName > b?.authName ? 1 : -1),
//   render: (text: string | null, record: Record<string, any>) => {
//     return (
//       <Tooltip title={tooltipLength(text, 100)}>
//         <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '认证状态',
//   dataIndex: 'stateName',
//   key: 'stateName',
//   width: 120,
//   visible: false,
//   render: (text: string | null) => {
//     const { colorText, color } = getColorTextLoadMap(text);
//     return (
//       <span className={pageStyles['over-flow-hidden']} style={{ color }}>
//         {colorText ? colorText : '--'}
//       </span>
//     );
//   },
// },
// {
//   title: '经营范围',
//   dataIndex: 'businessScope',
//   key: 'businessScope',
//   width: 200,
//   visible: false,
//   render: (text: string | null, record: Record<string, any>) => {
//     return (
//       <Tooltip title={tooltipLength(text, 100)}>
//         <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '评测等级',
//   dataIndex: 'scoreLevelName',
//   key: 'scoreLevelName',
//   width: 120,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.scoreLevel > b?.scoreLevel ? 1 : -1),
//   render: (text: string | null) => {
//     const { colorText, color } = getColorTextLoadMap(text);
//     return (
//       <span
//         className={pageStyles['over-flow-hidden']}
//         style={{
//           color,
//         }}
//       >
//         {colorText ? colorText : '--'}
//       </span>
//     );
//   },
// },
// {
//   title: '评测得分',
//   dataIndex: 'scoreNum',
//   key: 'scoreNum',
//   width: 120,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.scoreNum > b?.scoreNum ? 1 : -1),
//   render: (text: string | null) => {
//     return (
//       <Tooltip title={text ? tooltipLength(text, 50) : ''}>
//         <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '评测时间',
//   dataIndex: 'scoreTime',
//   key: 'scoreTime',
//   width: 150,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.scoreTime > b?.scoreTime ? 1 : -1),
//   render: (text: string | null) => {
//     return (
//       <Tooltip title={text ? text : ''}>
//         <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
//       </Tooltip>
//     );
//   },
// },
// {
//   title: '是否黑名单',
//   dataIndex: 'isBlack',
//   key: 'isBlack',
//   width: 140,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.isBlack > b?.isBlack ? 1 : -1),
//   render: (text: string, record: Record<string, any>) => {
//     return (
//       <>
//         <Switch
//           checkedChildren="是"
//           unCheckedChildren="否"
//           checked={text == '1' ? true : false}
//           onChange={(_checked: boolean, e: any) => {
//             e?.stopPropagation();
//             clickFnc?.onPullBlack(record);
//           }}
//           disabled={curRes?.['/supplierInfoController/pullBlack'] && record?.isBlack == '0' ? false : true}
//         />
//       </>
//     );
//   },
// },
// {
//   title: '是否年检',
//   dataIndex: 'isInspect',
//   key: 'isInspect',
//   width: 120,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.isInspect > b?.isInspect ? 1 : -1),
//   render: (text: string | null, record: Record<string, any>) => {
//     let newText: string = '';
//     let color: string = '';
//     if (text == '0') {
//       newText = '否';
//       color = '#d4380d';
//     } else if (text == '1') {
//       newText = '是';
//       color = '#52c41a';
//     }
//     return (
//       <span
//         className={pageStyles['over-flow-hidden']}
//         style={{
//           color,
//         }}
//       >
//         {newText ? newText : '--'}
//       </span>
//     );
//   },
// },
// {
//   title: '默认税率',
//   dataIndex: 'rateNum',
//   key: 'rateNum',
//   width: 120,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.rateNum > b?.rateNum ? 1 : -1),
//   render: (text: string | null) => {
//     return <span className={pageStyles['over-flow-hidden']}>{text ? `${text}%` : '--'}</span>;
//   },
// },
// {
//   title: '注册资本（万元）',
//   dataIndex: 'registerCapital',
//   key: 'registerCapital',
//   width: 150,
//   visible: false,
//   sorter: (a: any, b: any) => (a?.registerCapital > b?.registerCapital ? 1 : -1),
//   render: (text: string | null, record: Record<string, any>) => {
//     return (
//       <Tooltip title={tooltipLength(text, 100)}>
//         <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
//       </Tooltip>
//     );
//   },
// },
